package collection;

import java.util.*;

public class SortPoint {
    public static void main(String[] args) {
        Random r = new Random();
        List<Point> list = new ArrayList<>();

        list.add(new Point(r.nextInt(10),r.nextInt(100) ));
        list.add(new Point(r.nextInt(10),r.nextInt(100) ));
        list.add(new Point(r.nextInt(10),r.nextInt(100) ));
        list.add(new Point(r.nextInt(10),r.nextInt(100) ));
        list.add(new Point(r.nextInt(10),r.nextInt(100) ));
        list.add(new Point(r.nextInt(10),r.nextInt(100) ));

        System.out.println("list原始数据:"+list);


        list.sort(new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int len1 =o1.getX()^2+ o1.getY()^2;
                int len2 = o2.getX()^2+ o2.getY()^2;
                return len1-len2 ;
            }
        });
        System.out.println(list);

//        Collections.sort(list, new Comparator<Point>() {
//            @Override
//            public int compare(Point o1, Point o2) {
//                int len1 =o1.getX()^2+ o1.getY()^2;
//                int len2 = o2.getX()^2+ o2.getY()^2;
//                return len1-len2 ;
//            }
//        });

    }
}
